﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using edu.Model;
using Discuz.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Data;

namespace edu.Service
{

    public class PatriarchService
    {
        public static int Add(Patriarch entity)
        {
            int id = 0;
            string sql = "insert into edu_patriarch([Code],[Name],[Description],UserId) values(@Code,@Name,@Description,@UserId)";
            DbParameter[] param ={
                new SqlParameter(){DbType=DbType.String, ParameterName="Code", Value=entity.Code},
                new SqlParameter(){DbType=DbType.String, ParameterName="Name", Value=entity.Name},
                new SqlParameter(){DbType=DbType.String, ParameterName="Description", Value=entity.Description},
                new SqlParameter(){DbType=DbType.String, ParameterName="UserId", Value=entity.UserId}
                                };
            DbHelper.ExecuteNonQuery(out id, CommandType.Text, sql, param);
            return id;
        }

        public static void Update(Patriarch entity)
        {
            string sql = string.Format("update [edu_patriarch] set [Code]=@Code,[Name]=@Name,[Description]=@Description,[UserId]=@UserId where Id=@Id");
            DbParameter[] param ={
                new SqlParameter(){DbType=DbType.String, ParameterName="Code", Value=entity.Code},
                new SqlParameter(){DbType=DbType.String, ParameterName="Name", Value=entity.Name},
                new SqlParameter(){DbType=DbType.String, ParameterName="Description", Value=entity.Description},
                new SqlParameter(){DbType=DbType.String, ParameterName="UserId", Value=entity.UserId},
                new SqlParameter(){DbType=DbType.String, ParameterName="Id", Value=entity.Id}
                                };
            DbHelper.ExecuteNonQuery(CommandType.Text, sql, param);
        }

        public static void Delete(Patriarch entity)
        {
            throw new NotImplementedException();
        }

        public static void Delete(int id)
        {
            string sql = string.Format("delete from edu_patriarch where Id=@Id");
            DbParameter[] param ={
                new SqlParameter(){DbType=DbType.String, ParameterName="Id", Value=id}
                              };
            DbHelper.ExecuteNonQuery(CommandType.Text, sql, param);
        }
    }
}
